<%@page import="com.liferay.portal.kernel.util.Validator"%>
<%@ include file="/html/init.jsp" %>

<style type="text/css">
#map_canvas {
	min-width: 100%;
	min-height: 200px;
}
</style>

<script type="text/javascript">
	var <portlet:namespace />map;
    var <portlet:namespace />initialLocation;

    var lattitude = '<%= location.getLatitude() %>';
    var longitude = '<%= location.getLongitude() %>'; 
    
    var city = '<%= location.getCity() %>';
   
    var geocoder;
    var <portlet:namespace />map;
    function <portlet:namespace />initialize() {
    	
    	geocoder = new google.maps.Geocoder();
        var myLatlng = new google.maps.LatLng(lattitude, longitude);
        var myOptions = {
            zoom : 5,
            center : myLatlng,
            disableDefaultUI: true,
            mapTypeId : google.maps.MapTypeId.ROADMAP
        };
        
        
        <portlet:namespace />map = new google.maps.Map(document
                .getElementById("map_canvas"), myOptions);
        var marker;
        
        if(null==lattitude  && null==longitude){
        	 
        	marker = new google.maps.Marker({
                map : <portlet:namespace />map,
                position : myLatlng,
                title:"You are here"
            });
        	
        }else {
        	 
        	geocoder.geocode( { 'address': city}, function(results, status) {
    			if (status == google.maps.GeocoderStatus.OK) {
    				 
    				<portlet:namespace />map.setCenter(results[0].geometry.location);
    				marker = new google.maps.Marker({
    					map: <portlet:namespace />map,
    					position: results[0].geometry.location,
    					title:"You are here"
    				});
    			} else {
    				alert("Geocode was not successful for the following reason: " + status);
    			}
        	}); 
        }
    }

    function <portlet:namespace />loadScript() {
        var script = document.createElement("script");
        script.type = "text/javascript";
        script.src = "http://maps.google.com/maps/api/js?sensor=false&callback=<portlet:namespace />initialize";
        document.body.appendChild(script);
    }

    window.onload = <portlet:namespace />loadScript;
</script>

<div id="map_canvas"></div>